#include"GlobalDef.h"
#include"DEMOGameState_Base.h"
#include"DEMOGameState_Context.h"
#include"DEMOInput_Helper.h"

#include<iostream>
using namespace std;

bool DEMOInputHelper::bCareMouseEvent = false;

bool DEMOInputHelper::IsEventValid(hgeInputEvent theEvent)
{
	if( theEvent.type < INPUT_KEYDOWN || theEvent.type > INPUT_MOUSEWHEEL)
	{
		return false;	
	}

	if( !bCareMouseEvent && 
		(theEvent.type >=INPUT_MBUTTONDOWN && theEvent.type <=INPUT_MOUSEWHEEL))
	{
		return false;
	}

	return true;
}

char* DEMOInputHelper::GetEventTypeToStr(hgeInputEvent theEvent)
{
	switch(theEvent.type)
	{
	case INPUT_KEYDOWN:
		return "INPUT_KEYDOWN";
	case INPUT_KEYUP:
		return "INPUT_KEYUP";
	case INPUT_MBUTTONDOWN:
		return "INPUT_MBUTTONDOWN";
	case INPUT_MBUTTONUP:
		return "INPUT_MBUTTONUP";
	case INPUT_MOUSEMOVE:
		return "INPUT_MOUSEMOVE";
	case INPUT_MOUSEWHEEL:
		return "INPUT_MOUSEWHEEL";
	default:
		return "UNKNOWN EVENT TYPE !!";
	}
}


bool DEMOInputHelper::ProcessInput_Helper(hgeInputEvent theEvent)
{
	if( IsEventValid(theEvent) )
	{
		cout << theEvent.chr << "\t" << theEvent.key <<"\t" << theEvent.type << endl;
		printf("%c\t%d\t%s",theEvent.chr,theEvent.key,GetEventTypeToStr(theEvent));
	}
	
	if(g_GameState!=NULL)
	{
		DEMOGameState_Base *curGameState;
		if((curGameState =  g_GameState->GetGameState())!=NULL)
		{
			return curGameState->OnInput(theEvent);
		}
	}
	return false;
}